<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ] 
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/3/4-16:21
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\admin\controller;


    use app\admin\service\ModelService;

    class Model extends AdminBase
    {

        public function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub

            $this->model=app()->model("models");

        }


        /**
         * @return mixed
         * @throws \think\Exception
         * @throws \think\exception\PDOException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/12 0012
         * @name: addModel
         * @describe:
         */
        public function addModel(){
            if (IS_POST){
                $data = $this->request->post();

                if (isset($data['id'])){
                    addLog("模型修改操作","修改模型：".$data['name']);
                }else{
                    addLog("模型添加操作","新增模型：".$data['name']);
                }
                return $this->model->addAndEdit($data);
            }

            return $this->fetch();

        }




        /**
         * @return mixed
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/4
         * @name: editModel
         * @describe:编辑
         */
        public function editModel(){
            $id=$this->request->param("id/d");

            $info = $this->model->getOne(['id'=>$id]);

            if (empty($info)){
                $this->assign('msg','当前id:'.$id.'错误');
                $this->fetch("public/404");
            }

            $this->assign(compact("info"));

            return $this->fetch();
        }
    }